package cz.studio.stripes.action;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import cz.studio.dao.UzivatelDao;
import cz.studio.entity.Adresa;
import cz.studio.entity.Uzivatel;
import cz.studio.service.UzivatelImpl;
import cz.studio.stripes.action.parent.AbstractAction;
import cz.studio.stripes.bean.Mas102Bean;

@UrlBinding(value = "/Mas102.action")
public class Mas102 extends AbstractAction{
	private static final String CURRENT_JSP = "/Mas102.jsp";
	
	private Mas102Bean actionBean;
	private UzivatelDao d = new UzivatelDao();
	private UzivatelImpl uzivatelService = new UzivatelImpl();
	private Integer idcko;

	public Integer getIdcko() {
		return idcko;
	}

	public void setIdcko(Integer idcko) {
		this.idcko = idcko;
	}

	@DefaultHandler
	public Resolution resolution() {
		return new ForwardResolution(CURRENT_JSP);
	}
	
	public Resolution novy() {
		actionBean = new Mas102Bean();
		actionBean.setNovy(true);
		actionBean.setUzivatel(new Uzivatel());
		actionBean.getUzivatel().setAdresa(new Adresa());
		return new ForwardResolution(CURRENT_JSP);
	}
	
	public Resolution edit() {
		actionBean = new Mas102Bean();
		actionBean.setNovy(false);
		System.out.println(idcko);
		actionBean.setUzivatel(d.find(idcko));
		return new ForwardResolution(CURRENT_JSP);
	}
	
	public Resolution uloz() {
		uzivatelService.ulozUzivatele(actionBean.getUzivatel(), actionBean.isNovy());
		return new RedirectResolution(Mas101.class);
	}

	public void setActionBean(Mas102Bean actionBean) {
		this.actionBean = actionBean;
	}

	public Mas102Bean getActionBean() {
		return actionBean;
	}
}